#ifndef _AUTOPTR_H_
#define _AUTOPTR_H_

/**
 * Auto free a point.
 * NO NOT use for array point
 */
template<typename _Tp>
class CAutoPtr
{
public:
	typedef _Tp	element_type;

public:
	CAutoPtr(element_type* __p = NULL) throw(): _M_ptr(__p) { }
	~CAutoPtr() { Free();}
public:
	element_type&	operator*() const throw()  { return *_M_ptr; }
	element_type*	operator->() const throw() { return _M_ptr; }
	void Clear() { _M_ptr = NULL;}
	void Free() { if(_M_ptr) delete _M_ptr; _M_ptr = NULL;}

protected:
	element_type*	_M_ptr;	
};

/**
 * Auto free a array point
 */
template<typename _Tp>
class CAutoPtrArray
{
public:
	typedef _Tp	element_type;

public:
	CAutoPtrArray(element_type* __p = NULL) throw(): _M_ptr(__p) { }
	~CAutoPtrArray() { Free();}
public:
	element_type&	operator*() const throw()  { return *_M_ptr; }
	element_type*	operator->() const throw() { return _M_ptr; }
	void Clear() { _M_ptr = NULL;}
	void Free() {if(_M_ptr) delete[] _M_ptr; _M_ptr = NULL;}

protected:
	element_type*	_M_ptr;	
};

#endif// _AUTOPTR_H_
